package com.lwx.chapter9;

//不适用线段树的方法
public class NumArray2 {
    //sum[i] 存储的是data[0,i]之间的和
    private int[] sum;
    public NumArray2(int[] nums) {
        sum = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j <= i ; j++) {
                sum[i] += nums[j];
            }
        }
    }
    public int sumRange(int i, int j) {
        if(i < 0 || j > sum.length-1){
            throw new IllegalArgumentException("Index is error");
        }
        if(i > 0){
            return sum[j] - sum[i-1];
        }else {
            return sum[j];
        }

    }

    //将nums的index索引位置改为val
    public void update(int index, int val) {

    }
}
